﻿using Modules;
using Modules.Corp;
using PmSoft;
using System.Security.Authentication;

namespace ManagementApi.Mvc.ApplicationContexts;

/// <summary>
/// 项目指挥部请求上下文
/// </summary>
[UseDI(ServiceLifetime.Scoped)]
public class ProjectCommanderApplicationContext : ProjectUserApplicationContext
{
    public ProjectCommanderApplicationContext(IServiceProvider serviceProvider) : base(serviceProvider)
    {
    }

    private CommanderInfo? _commanderInfo = null;

    /// <summary>
    /// 当前登录的项目指挥部信息
    /// </summary>
    public CommanderInfo CurrentCommander
    {
        get
        {
            if (_commanderInfo != null)
                return (CommanderInfo)_commanderInfo;

            if (CurrentUser == null || CurrentUser is not CommanderInfo commanderInfo)
                throw new AuthenticationException("当前非项目指挥部用户类型");
            _commanderInfo = commanderInfo;
            return _commanderInfo;
        }
    }
}
